package com.zhongyu.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhongyu.pojo.StoreDetail;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface StoreDetailMapper extends BaseMapper<StoreDetail> {
    @Select("SELECT t1.*,t2.name,t3.sname FROM smbms_store_detail t1 JOIN smbms_goods t2 ON t1.good_id=t2.id JOIN smbms_store t3 ON t1.store_id=t3.id ${ew.customSqlSegment}")
    @ResultMap("sdRm")
    List<StoreDetail> findAll(Page page, @Param("ew") Wrapper wrapper);
    @Select("UPDATE smbms_store_detail SET number=number+#{number} WHERE store_id=#{storeId} AND good_id=#{goodId}")
    void update( @Param("storeId")Integer storeId, @Param("goodId")Integer goodId,  @Param("number")Integer number);
    @Select("UPDATE smbms_store_detail SET number=number-#{number} WHERE store_id=#{storeId} AND good_id=#{goodId}")
    void  updatejian(@Param("storeId")Integer storeId,@Param("goodId")Integer goodId,@Param("number")Integer number);
    @Select("UPDATE smbms_store_detail SET number=#{number} WHERE store_id=#{storeId} AND good_id=#{goodId}")
    void  updateChu( @Param("storeId")Integer storeId, @Param("goodId")Integer goodId,  @Param("number")Integer number);
    @Select("SELECT number FROM smbms_store_detail WHERE store_id=#{storeId} AND good_id=#{goodId}")
    Integer select( @Param("storeId")Integer storeId, @Param("goodId")Integer goodId);
@Select("INSERT INTO smbms_store_detail ( store_id, good_id,number) VALUES(#{storeId},#{goodId},#{number})")
    void zeng( @Param("storeId")Integer storeId, @Param("goodId")Integer goodId,  @Param("number")Integer number);
    @Select("SELECT t1.*,t2.name FROM smbms_store_detail t1 JOIN smbms_goods t2 ON t1.good_id= t2.id")
    @ResultMap("sdRm")
    List<StoreDetail> searchgoods();
    @Select("SELECT t1.*,t2.sname FROM smbms_store_detail t1 JOIN  smbms_store t2 ON t1.store_id=t2.id WHERE good_id=#{goodId}")
    @ResultMap("sdRm")
    List<StoreDetail>  searchStoreId(Integer goodId);
}
